package com.example.helloworld;

import java.io.*;

public class RunoobDemo {
    public static void main(String[] args) {
        // 读取文件（但是没有关闭资源）
//        String line;
//        try(BufferedReader br = new BufferedReader(new FileReader("C:/Users/47054/Desktop/hello/aa.txt"))) {
//            while ((line = br.readLine()) != null) {
//                System.out.println("Line =>"+line);
//            }
//        } catch (IOException e) {
//            System.out.println("IOException in try block =>" + e.getMessage());
//        }
        // 读取文件（读取后，且关闭资源）
        BufferedReader br = null;
        PrintWriter pw = null;
        String line;
        // 克隆
        try {
            br = new BufferedReader(new FileReader("C:/Users/47054/Desktop/hello/aa.txt"));
            pw = new PrintWriter(new File("C:/Users/47054/Desktop/hello/bb.txt"));
            while ((line = br.readLine()) != null){
//                System.out.println(line);
                pw.println(line);
            }
        } catch (IOException e){
            System.out.println("IOException in try block =>" + e.getMessage());
        } finally {
           try {
               if(br != null) {
                   br.close();
                   pw = null;
                   System.out.println("资源已经释放！！"+pw);
               }
           } catch (IOException e){
               System.out.println("IOException in finally block =>"+e.getMessage());
           }
        }
    }
}
